package cn.com.dev;

import cn.com.elite.Util;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;

public class UploadImage_Test {
    @Test
    public void normal() throws Exception {
        // 设定服务地址
        String serverUrl = "http://xxxxxxxxxxxxxxxx";//上传地址

        // 设定要上传的普通Form Field及其对应的value
        ArrayList<FormFieldKeyValuePair> ffkvp = new ArrayList<FormFieldKeyValuePair>();
        ffkvp.add(new FormFieldKeyValuePair("subject", "subject"));//其他参数
        ffkvp.add(new FormFieldKeyValuePair("faxnumber", "18675571253"));
        ffkvp.add(new FormFieldKeyValuePair("token", "tokentokentokentokentokentokentokentoken"));

        // 设定要上传的文件
        ArrayList<UploadFileItem> ufi = new ArrayList<UploadFileItem>();
        ufi.add(new UploadFileItem("rawfile", System.getProperty("user.dir") + "/src/test/resources/123.jpg"));
        HttpPostEmulator hpe = new HttpPostEmulator();
        String response = hpe.sendHttpPostRequest(serverUrl, ffkvp, ufi);
        System.out.println("Responsefrom server is: " + response);

        //对 imageUrl、thumbnailUrl、shortUrl进行获取，不能返回空
        HttpClient httpClient = new HttpClient();
        GetMethod getMethod = new GetMethod();
        System.out.println("Responsefrom server is: " + httpClient.executeMethod(getMethod));
        if (httpClient.executeMethod(getMethod) != HttpStatus.SC_OK) {
            Assert.fail("imageUrl 内容不存在.");
        }

    }


}